{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "943366c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "from xml.dom.minidom import parse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "bfe0f4f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "domTree = parse('../XML/UDS-List.xml')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "2a9d31da",
   "metadata": {},
   "outputs": [],
   "source": [
    "rootNode = domTree.documentElement"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "f93f12f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "udsInstances = rootNode.getElementsByTagName('UdsDescription')\n",
    "udsInstanceDict = {}\n",
    "udsInstanceParamDict = {}\n",
    "for udsInstcance in udsInstances:\n",
    "    udsDes = udsInstcance.getAttribute('comments')\n",
    "    udsSid = udsInstcance.getElementsByTagName('UdsSid')[0].childNodes[0].data\n",
    "    udsParas = udsInstcance.getElementsByTagName('parameter')\n",
    "    udsInstanceDict[udsDes] = {\n",
    "            'udsSid' : udsSid,\n",
    "            'ParamDict':{}\n",
    "        }\n",
    "    for udsPara in udsParas:\n",
    "        paraName =  udsPara.getAttribute('comments')\n",
    "        paraValue =  udsPara.childNodes[0].data\n",
    "        udsInstanceDict[udsDes]['ParamDict'].update({paraName:paraValue})\n",
    "#         udsInstanceParamDict[paraName] = {\n",
    "#            'paraValue': paraValue, \n",
    "#         }\n",
    "#         udsInstanceDict[udsDes]['ParamDict'].update(udsInstanceParamDict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "29dd2dbd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'DiagnosticSessionControl': {'udsSid': '0x10',\n",
       "  'ParamDict': {'defaultSession': '0x01',\n",
       "   'ProgrammingSession': '0x02',\n",
       "   'extendedDiagnosticSession': '0x03',\n",
       "   'safetySystemDiagnosticSession': '0x04'}},\n",
       " 'ECUReset': {'udsSid': '0x11',\n",
       "  'ParamDict': {'hardReset': '0x01',\n",
       "   'keyOffOnReset': '0x02',\n",
       "   'softReset': '0x03'}},\n",
       " 'SecurityAccess': {'udsSid': '0x27',\n",
       "  'ParamDict': {'requestSeed_01': '0x01', 'sendKey_02': '0x02'}}}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "udsInstanceDict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "f550a01f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['DiagnosticSessionControl', 'ECUReset', 'SecurityAccess'])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "udsInstanceDict.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "1bc80678",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DiagnosticSessionControl\n",
      "{'udsSid': '0x10', 'ParamDict': {'defaultSession': '0x01', 'ProgrammingSession': '0x02', 'extendedDiagnosticSession': '0x03', 'safetySystemDiagnosticSession': '0x04'}}\n",
      "0x10\n",
      "dict_keys(['defaultSession', 'ProgrammingSession', 'extendedDiagnosticSession', 'safetySystemDiagnosticSession'])\n",
      "ECUReset\n",
      "{'udsSid': '0x11', 'ParamDict': {'hardReset': '0x01', 'keyOffOnReset': '0x02', 'softReset': '0x03'}}\n",
      "0x11\n",
      "dict_keys(['hardReset', 'keyOffOnReset', 'softReset'])\n",
      "SecurityAccess\n",
      "{'udsSid': '0x27', 'ParamDict': {'requestSeed_01': '0x01', 'sendKey_02': '0x02'}}\n",
      "0x27\n",
      "dict_keys(['requestSeed_01', 'sendKey_02'])\n"
     ]
    }
   ],
   "source": [
    "for instanceKey in udsInstanceDict:\n",
    "    print(instanceKey)\n",
    "    print(udsInstanceDict[instanceKey])\n",
    "    print(udsInstanceDict[instanceKey]['udsSid'])\n",
    "    print(udsInstanceDict[instanceKey]['ParamDict'].keys())\n",
    "    for udsss in udsInstanceDict[instanceKey]:\n",
    "        pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "97c20d9a",
   "metadata": {},
   "outputs": [],
   "source": [
    "rootLists =  rootNode.getElementsByTagName('UdsDescription')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "id": "05f7702e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DiagnosticSessionControl\n",
      "0x10\n",
      "defaultSession\n",
      "0x01\n",
      "ProgrammingSession\n",
      "0x02\n",
      "extendedDiagnosticSession\n",
      "0x03\n",
      "safetySystemDiagnosticSession\n",
      "0x04\n",
      "ECUReset\n",
      "0x11\n",
      "hardReset\n",
      "0x01\n",
      "keyOffOnReset\n",
      "0x02\n",
      "softReset\n",
      "0x03\n",
      "SecurityAccess\n",
      "0x27\n",
      "requestSeed_01\n",
      "0x01\n",
      "sendKey_02\n",
      "0x02\n"
     ]
    }
   ],
   "source": [
    "for rootList in rootLists:\n",
    "    print(rootList.getAttribute('comments'))\n",
    "    SidLists = rootList.getElementsByTagName('UdsSid')\n",
    "    for SidList in SidLists:\n",
    "        print(SidList.childNodes[0].data)\n",
    "    ParLists = rootList.getElementsByTagName('parameter')\n",
    "#     print(ParLists)\n",
    "    for ParList in ParLists:\n",
    "        print(ParList.getAttribute('comments'))\n",
    "        print(ParList.childNodes[0].data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "108b0906",
   "metadata": {},
   "outputs": [],
   "source": [
    "class A():\n",
    "    def __init__(self):\n",
    "        self.a = None\n",
    "        self.b = None\n",
    "    def setValue(self,aa,bb):\n",
    "        self.a = aa\n",
    "        self.b = bb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "2fee750c",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = A()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "3af92979",
   "metadata": {},
   "outputs": [],
   "source": [
    "a.setValue(1,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b51b63fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "fcf16dcb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "375e9750",
   "metadata": {},
   "outputs": [],
   "source": [
    "b = A()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "bc3ce262",
   "metadata": {},
   "outputs": [],
   "source": [
    "b.b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "625dda5a-049c-4747-8da1-90c8e2b6d209",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0eb28d2c-c25f-49e0-848e-6cb628704131",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b3ef4b78",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "52682515",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20c0923d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f4a23317",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dabb6165",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "52fe0c54",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d95cd028",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2686c5a9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2fa581ca",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de436738",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0640fa49",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9760d724",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "30bd4c43",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "564e0dc0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3a075f2b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d8b54bf",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "90c1c0f9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ea78efb2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7a70205e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "21a0e2fe",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e5632b6a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c53aab1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9eec56c7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d7b56a71",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a49b461",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "966a040d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85475ca0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c7e3ac4f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e79bd3e3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fee894e1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20606a95",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3ca0926a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
